package cn.itcast.p2p20.fragments;


import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.itcast.p2p20.R;
import cn.itcast.p2p20.bean.TestData;
import cn.itcast.p2p20.bean.request.TestRequest;
import cn.itcast.p2p20.bean.response.TestResponse;
import cn.itcast.p2p20.net.BaseRequest;
import cn.itcast.p2p20.net.SuccessResultCallback;

/**
 * A simple {@link Fragment} subclass.
 */
public class MoreFragment extends BaseFragment implements SuccessResultCallback<TestResponse> {

    @InjectView(R.id.textview)
    TextView textView;

//    @InjectView(R.id.statelayout_id)
//    StateLayout statelayoutId;

    @Override
    protected void initData() {

        sendRequest(new TestRequest(), TestResponse.class, this);

        //NetUtil.sendRequest(new TestRequest(), TestResponse.class, this);

       /* new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                textView.setText("获取数据成功");
                showSuccessStateLayout();
            }
        }, 3000);*/
    }

    @Override
    protected void initView(View childFragmentView) {

        ButterKnife.inject(this, childFragmentView);
    }

    @Override
    protected String getTitle() {
        return null;
    }

    @Override
    protected int getContentLayoutRes() {
        return R.layout.fragment_more;
    }

    @Override
    public void onSuccessResult(BaseRequest request, TestResponse response) {

        TestData testData = response.data;
        textView.setText(testData.toString());
    }

   /* @Override
    public void onSuccess(BaseRequest request, TestResponse reponse) {

        TestData testData = reponse.data;
        textView.setText(testData.toString());
        showSuccessStateLayout();
    }

    @Override
    public void onOther(BaseRequest request, TestResponse reponse) {

        Toast.makeText(mContext, "其他错误", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onError(BaseRequest request, Exception e) {

        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
*/
   /* @OnClick({R.id.bt_loading, R.id.bt_error, R.id.bt_empty, R.id.bt_success})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_loading:
                statelayoutId.showStateView(StateLayout.STATE_LOADING);
                break;
            case R.id.bt_error:
                statelayoutId.showStateView(StateLayout.STATE_ERROR);
                break;
            case R.id.bt_empty:
                statelayoutId.showStateView(StateLayout.STATE_EMPTY);
                break;
            case R.id.bt_success:
                //statelayoutId.addStateLayout(StateLayout.STATE_SUCCESS, R.layout.activity_welcome);
                statelayoutId.showStateView(StateLayout.STATE_SUCCESS);
                ///statelayoutId.addStateView(StateLayout.STATE_ERROR, null);
                break;
        }
    }*/
}
